
package ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.Html;
import android.text.Spanned;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import Utils.StringUtil;
import base.BaseViewHolder;
import base.SuperBaseAdapter;
import dao.MerchantTradeItem;


/**
 * 交易明细适配器
 * Created by chenjian on 19/2/27.
 */
public class MerchantTradeAdapter extends SuperBaseAdapter<MerchantTradeItem> {

    List<MerchantTradeItem> mData = new ArrayList<>();
    Context mContext;

    public MerchantTradeAdapter(Context context, List<MerchantTradeItem> data) {
        super(context, data);
        mContext = context;
        mData = data;
    }

    @Override
    protected void convert(BaseViewHolder holder, final MerchantTradeItem item, final int position) {
        holder.setText(R.id.trade_amount, "交易金额：" + StringUtil.getFormatPrice(item.getTradeAmount()) + " 元");
        holder.setText(R.id.trade_time, "交易时间：" + StringUtil.getFormatDate(item.getBusinessTime()));
        if (item.getMerchantLevel().equals("1")) {
            holder.setTextColor(R.id.trade_amount, Color.parseColor("#17AB28"));
            holder.setTextColor(R.id.trade_time, Color.parseColor("#17AB28"));
            Spanned str1 = Html.fromHtml("<font color=#17AB28>分润收益：</font><font color=#FE3333>" + item.getDividedAmount() + "元</font>");
            Spanned str2 = Html.fromHtml("<font color=#17AB28>交易类型：</font><font color=#0CA6F0>" + item.getTradeType() + "</font>");
            holder.setText(R.id.divide_amount, str1).setText(R.id.trade_type, str2);
        } else if (item.getMerchantLevel().equals("2")) {
            holder.setTextColor(R.id.trade_amount, Color.parseColor("#F86912"));
            holder.setTextColor(R.id.trade_time, Color.parseColor("#F86912"));
            Spanned str1 = Html.fromHtml("<font color=#F86912>分润收益：</font><font color=#FE3333>" + item.getDividedAmount() + "元</font>");
            Spanned str2 = Html.fromHtml("<font color=#F86912>交易类型：</font><font color=#0CA6F0>" + item.getTradeType() + "</font>");
            holder.setText(R.id.divide_amount, str1).setText(R.id.trade_type, str2);
        } else if (item.getMerchantLevel().equals("3")) {
            holder.setTextColor(R.id.trade_amount, Color.parseColor("#333333"));
            holder.setTextColor(R.id.trade_time, Color.parseColor("#333333"));
            Spanned str1 = Html.fromHtml("<font color=#333333>分润收益：</font><font color=#FE3333>" + item.getDividedAmount() + "元</font>");
            Spanned str2 = Html.fromHtml("<font color=#333333>交易类型：</font><font color=#0CA6F0>" + item.getTradeType() + "</font>");
            holder.setText(R.id.divide_amount, str1).setText(R.id.trade_type, str2);
        } else if (item.getMerchantLevel().equals("4")) {
            holder.setTextColor(R.id.trade_amount, Color.parseColor("#1232F8"));
            holder.setTextColor(R.id.trade_time, Color.parseColor("#1232F8"));
            Spanned str1 = Html.fromHtml("<font color=#1232F8>分润收益：</font><font color=#FE3333>" + item.getDividedAmount() + "元</font>");
            Spanned str2 = Html.fromHtml("<font color=#1232F8>交易类型：</font><font color=#0CA6F0>" + item.getTradeType() + "</font>");
            holder.setText(R.id.divide_amount, str1).setText(R.id.trade_type, str2);
        } else {
            holder.setTextColor(R.id.trade_amount, Color.parseColor("#333333"));
            holder.setTextColor(R.id.trade_time, Color.parseColor("#333333"));
            Spanned str1 = Html.fromHtml("<font color=#333333>分润收益：</font><font color=#FE3333>" + item.getDividedAmount() + "元</font>");
            Spanned str2 = Html.fromHtml("<font color=#333333>交易类型：</font><font color=#0CA6F0>" + item.getTradeType() + "</font>");
            holder.setText(R.id.divide_amount, str1).setText(R.id.trade_type, str2);
        }

    }


    @Override
    protected int getItemViewLayoutId(int position, MerchantTradeItem item) {
        return R.layout.item_merchant_trade;
    }

}
